package com.openbravo.data.loader;

import com.openbravo.basic.BasicException;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;

public class StaticSentence extends JDBCSentence
{
  private static Logger logger = Logger.getLogger("com.openbravo.data.loader.StaticSentence");
  private ISQLBuilderStatic m_sentence;
  protected SerializerWrite m_SerWrite = null;
  protected SerializerRead m_SerRead = null;
  private Statement m_Stmt;

  public StaticSentence(Session paramSession, ISQLBuilderStatic paramISQLBuilderStatic, SerializerWrite paramSerializerWrite, SerializerRead paramSerializerRead)
  {
    super(paramSession);
    this.m_sentence = paramISQLBuilderStatic;
    this.m_SerWrite = paramSerializerWrite;
    this.m_SerRead = paramSerializerRead;
    this.m_Stmt = null;
  }

  public StaticSentence(Session paramSession, ISQLBuilderStatic paramISQLBuilderStatic)
  {
    this(paramSession, paramISQLBuilderStatic, null, null);
  }

  public StaticSentence(Session paramSession, ISQLBuilderStatic paramISQLBuilderStatic, SerializerWrite paramSerializerWrite)
  {
    this(paramSession, paramISQLBuilderStatic, paramSerializerWrite, null);
  }

  public StaticSentence(Session paramSession, String paramString, SerializerWrite paramSerializerWrite, SerializerRead paramSerializerRead)
  {
    this(paramSession, new NormalBuilder(paramString), paramSerializerWrite, paramSerializerRead);
  }

  public StaticSentence(Session paramSession, String paramString, SerializerWrite paramSerializerWrite)
  {
    this(paramSession, new NormalBuilder(paramString), paramSerializerWrite, null);
  }

  public StaticSentence(Session paramSession, String paramString)
  {
    this(paramSession, new NormalBuilder(paramString), null, null);
  }

  public DataResultSet openExec(Object paramObject)
    throws BasicException
  {
//	  if(true)
//		  throw new RuntimeException("aa");
    closeExec();
    try
    {
      this.m_Stmt = this.m_s.getConnection().createStatement();
      //m sentence com.openbravo.data.loader.NormalBuilder@6d0dda
      String str = this.m_sentence.getSQL(this.m_SerWrite, paramObject);
      logger.info("Executing static SQL: " + str);
      if (this.m_Stmt.execute(str))
        return new JDBCSentence.JDBCDataResultSet(this.m_Stmt.getResultSet(), this.m_SerRead);
      int i = this.m_Stmt.getUpdateCount();
      if (i < 0)
        return null;
      return new SentenceUpdateResultSet(i);
    }
    catch (SQLException localSQLException)
    { throw new BasicException(localSQLException);
    }
   
  }

  public void closeExec()
    throws BasicException
  {
    if (this.m_Stmt != null)
      try
      {
        this.m_Stmt.close();
      }
      catch (SQLException localSQLException)
      {
        throw new BasicException(localSQLException);
      }
      finally
      {
        this.m_Stmt = null;
      }
  }

  public DataResultSet moreResults()
    throws BasicException
  {
    try
    {
      if (this.m_Stmt.getMoreResults())
        return new JDBCSentence.JDBCDataResultSet(this.m_Stmt.getResultSet(), this.m_SerRead);
      int i = this.m_Stmt.getUpdateCount();
      if (i < 0)
        return null;
      return new SentenceUpdateResultSet(i);
    }
    catch (SQLException localSQLException)
    { throw new BasicException(localSQLException);
    }
    }
   
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.data.loader.StaticSentence
 * JD-Core Version:    0.6.0
 */